﻿using Hong.Common.RabbitMQ;
using Hong.IRepository.IRepository_SystemSettings;
using JWTExam.JwtHelper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace WeHongshibApI.Controllers.Controllers_SystemSettings.RBAC
{
    [Authorize]
    [ApiExplorerSettings(GroupName = "SystemSettings")]
    [Route("api/[controller]")]
    [ApiController]
    public class LoginController : ControllerBase
    {
        #region 构造器API注入
        private readonly ILogin _ILogin;
        private readonly JwtHelpers _JwtHeaders;
        public LoginController(ILogin login, JwtHelpers JwtHeaders)
        {
            _ILogin = login;
            _JwtHeaders = JwtHeaders;
        }
        #endregion

        #region 生成JWT
        [AllowAnonymous]
        [HttpGet, Route("Logoin")]
        public IActionResult Logoin(string PersonnelUserName, string PersonneIPassword)
        {
            var q = _ILogin.Lode(PersonnelUserName, PersonneIPassword);

            var token = _JwtHeaders.GenerateToken(PersonnelUserName);
            HttpContext.Response.Headers.Add("token", token);
            HttpContext.Response.Headers["Access-Control-Expose-Headers"] = "token";
            return Ok(q);


        }
        #endregion

        #region 登录
        /// <summary>
        /// 
        /// </summary>
        /// <param name="PersonnelUserName"></param>
        /// <param name="PasPersonneIPasswordsWord"></param>
        /// <returns></returns>
        [HttpPost, Route("Lode")]
        public IActionResult Lode(string PersonnelUserName, string PasPersonneIPasswordsWord)
        {
            var role = _ILogin.Lode(PersonnelUserName, PasPersonneIPasswordsWord);
            return Ok(role);

        }
        #endregion

    }
}
